using McMaster.Extensions.CommandLineUtils;

namespace Awesome.MyCommand;

/// <summary>
/// 主程序/命令
/// </summary>
[HelpOption("-h|--help", Description = "查看帮助")]
[Command(Name = "docker", Description = "以Docker为例演示一个命令行工具")]
[Subcommand(typeof(Containers), typeof(Images))]
public class GitCommand {
  readonly string _version = "v1.0.0";

  /// <summary>
  /// 查看版本
  /// </summary>
  [Option(CommandOptionType.NoValue, ShortName = "v", LongName = "version", Description = "版本信息")]
  public bool Version { get; }

  /// <summary>
  /// 执行命令
  /// </summary>
  /// <param name="app">当前命令行对象</param>
  /// <param name="console">上下文环境</param>
  /// <returns></returns>
  private int OnExecute (CommandLineApplication app, IConsole console) {
    if (Version) {
      console.WriteLine(_version);
      return 0;
    }

    //其他命令...

    app.ShowHelp();
    return 0;
  }
}